Kubernetes
Table of content
Main concepts
Container Runtime Interface (CRI)
The CRI
is the service that will handle the container created by Kubernetes
.
The most famous one is Docker
but others can be used such as containerd
that is today officialy pushed by Kubernetes
.
Docker
is now depracted by Kubernetes
cause it does not expose a standardized API
. Moreover, Docker
is not a CRI
but a wrapper allowing to easily manage the containerd
CRI
.
This, if you are deploying a brand new Kubernetes
infrastructure, it is recommended to use containerd
.
Master Node
This node is used to orchestrate all nodes.
It hosts the Kubernetes
API.
Pod Network Controller (PNC)
A Pod Network
is a way to allow communication between different nodes in the cluster.
Installing a PNC
is a way to save a lot of time by discharging the network configuration to another service.
Several PNC
exist. The most famous are :
Flannel
: thisPNC
is alayer 3
controller based onVLAN
Calico
: thisPNC
is alayer 2
controller base onNAT
et supporte lesnetworkPolicies
deKubernetes
via le fichier/etc/calico/calicoctl.cfg
Services
The services allows to expose an application running on pods
kubectl expose deployment/${deployementName} --type="NodePort" --port ${appPort} --target-port
Commands
List nodes
kubectl get nodes
List pods
kubectl get pods ${options}
--all-namespaces
: display all pods whatever their namespaces-l app=$appName
: display the pods related to an application. The$appName
must be the one set on application thedeployment
file.
Display information about a pod
kubectl describe pod ${podName}
The ${podName}
is the name displayed by the get pods
command.
Describe deployment
kubectl describe deployment ${deploymentName}
Execute command on a pod
kubectl exec -ti ${podName}
Install
Install the CRI
# Install contnaird
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
sudo echo "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" > /etc/apt sources.list.d/docker.list
sudo apt update
sudo apt install containerd
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
Install Kubernetes
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt update
apt install kubeadm kubelet kubectl -y
Network
sudo modprobe overlay
sudo br_netfilter
sudo modprobe br_netfilter
sudo swapoff -a
sudo sysctl -w net.ipv4.ip_forward=1
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
Init the master node
sudo kubeadm init --cri-socket /run/containerd/containerd.sock --pod-network-cidr=10.244.0.0/16
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install the PNC
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Resources
- Set up a cluster : https://phoenixnap.com/kb/install-kubernetes-on-ubuntu
- PNC summary : https://www.objectif-libre.com/fr/blog/2018/07/05/comparatif-solutions-reseaux-kubernetes/
- Create the first application : https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/
- Production readiness : https://learnk8s.io/production-best-practices